﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PhysicalEquation.Models.EquationModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Equations
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.EnableClientValidation(); %>
<div>
    <img src="../../Content/Images/BackButton.png" alt="add new equation" title="back" id="backImg" class="addItemButton">
        <%:Html.ActionLink("Back to Subjects", "index", "Subject", null, null)%> 
    </img>
</div>
<span style="font-size: 1.75em;"><%= Model.SubjectName %></span>
<img src="../../Content/Images/addEquationButton.png" alt="add new equation" title="add new equation" id="addNewEquation" class="addItemButton"/>
<br/>
<br/>
<span style="font-size: 1.20em;">Equations</span>
<br/>
<table id="equationsTable">
    <tr>
        <th>Number</th>
        <th>Name</th>
        <th>Comments</th>
        <th>Solved</th>
        <th>Author</th>
        <th>Publication date</th>
    </tr>
    <%foreach(var item in Model.Items) { %>
    <tr isResolved="<%:item.IsSolved%>">
        <td><%:item.Number%></td>
        <td><%:Html.ActionLink(item.Name, "Detail", "Equation", new { equationId = item.Id }, null)%> </td>
        <td><%:item.Comments%></td>
        <td><%:item.IsSolved%></td>
        <td><%:item.Author%></td>
        <td><%:item.Date%></td>
    </tr>
    <% } %>
</table>

<div title="equation" id="equationDialogDiv">
    
    <%using(Ajax.BeginForm("AddEquation", "Equation", new AjaxOptions()
                                                        {
                                                            HttpMethod = "POST",
                                                            InsertionMode = InsertionMode.InsertAfter,
                                                            UpdateTargetId = "equationsTable",
                                                            OnSuccess = "_onSuccess"
                                                        }))
        {%>
        <% Html.RenderPartial("AddEquationView", new PhysicalEquation.Models.EquationItemModel(){SubjectId = Model.SubjectId}); %>
        <% }%>
    </div>


</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
    <script language="javascript" type="text/javascript">
           $(document).ready(function () {
               $("#equationDialogDiv").dialog({
                   autoOpen: false,
                   height: 350,
                   width: 350,
                   modal: true,
                   show: "fade",
                   hide: "fade",
                   buttons: {
                       "Add": function () {
                           _onAddEquation();
                       },
                       "Cancel": function () {
                           $(this).dialog("close");
                       }
                   }
               });
               $("#addNewEquation").click(function () {
                   $("#equationDialogDiv").dialog("open");
                   return false;
               });
           });

           var _onAddEquation = function (e) {
               $.validator.unobtrusive.parse(document);
               $("#submitNewEquation").click();
           };

           var _onSuccess = function () {
               $("#equationDialogDiv").dialog("close");
           };
    </script>
</asp:Content>
